﻿using OpenTK;

namespace LDLib
{
    /// <summary>
    /// Vertex struct. Represents a 3-dimensional
    /// vertex that has a location, normal and
    /// UV coordinates. Also has tangent and
    /// bitangent components for advanced
    /// shader stuff. :)
    /// </summary>
    public struct Vertex
    {
        public Vector3 position;
        public Vector3 normal;
        public Vector2 uv;
        public Vector3 tangent;
        public Vector3 bitangent;

        public Vertex(Vector3 pos)
        {
            position = pos;
            normal = Vector3.Zero;
            uv = Vector2.Zero;
            tangent = Vector3.Zero;
            bitangent = Vector3.Zero;
        }

        public Vertex(Vector3 pos, Vector3 normal)
        {
            position = pos;
            this.normal = normal;
            uv = Vector2.Zero;
            tangent = Vector3.Zero;
            bitangent = Vector3.Zero;
        }

        public Vertex(Vector3 pos, Vector3 normal, Vector2 uv)
        {
            position = pos;
            this.normal = normal;
            this.uv = uv;
            tangent = Vector3.Zero;
            bitangent = Vector3.Zero;
        }

        public Vertex(Vertex other)
        {
            position = new Vector3(other.position.X, other.position.Y, other.position.Z);
            normal = new Vector3(other.normal.X, other.normal.Y, other.normal.Z);
            uv = new Vector2(other.uv.X, other.uv.Y);
            tangent = new Vector3(other.tangent.X, other.tangent.Y, other.tangent.Z);
            bitangent = new Vector3(other.bitangent.X, other.bitangent.Y, other.bitangent.Z);
        }

        /// <summary>
        /// Retrieves the size of the vertex struct in bytes
        /// </summary>
        /// <returns>Size of the struct in bytes</returns>
        public static int Size()
        {
            return Vector3.SizeInBytes * 4 + Vector2.SizeInBytes;
        }

        /// <summary>
        /// Retrieves a nice string representation of the vertex.
        /// </summary>
        /// <returns>A string representing the vertex</returns>
        public override string ToString()
        {
            return position.ToString();
        }
    }
}
